package com.example.park_management.controller;


import com.example.park_management.service.CarService_lh;
import com.example.park_management.service.FaceService_lh;
import com.example.park_management.utils.UUIDUtil_lh;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;

@Api(tags = "文件上传", description = "文件上传")
@RestController
@RequestMapping("/ai")
public class CommonController_lh {

    @Autowired
    private FaceService_lh faceServiceLh;


    @Autowired
    private CarService_lh carServiceLh;
    @ApiOperation(value = "上传文件", notes = "所有上传文件的入口，需要带入User的 token 和 uuid")
    @PostMapping("/face")
    public String face(@RequestParam("file") MultipartFile file) {

        try {

            InputStream inputStream = file.getInputStream();

            return faceServiceLh.get(inputStream);

        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }

    }

    @ApiOperation(value = "上传文件", notes = "所有上传文件的入口，需要带入User的 token 和 uuid")
    @PostMapping("/car")
    public String car(@RequestParam("file") MultipartFile file) {

        String uuid = UUIDUtil_lh.gen();
        String fileName = uuid + "." + file.getOriginalFilename().split("\\.")[1];
        try {

            InputStream inputStream = file.getInputStream();

            return carServiceLh.get(inputStream);



        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }

    }


}
